package com.itheima.zuoye.zy1;

import cn.hutool.core.io.FileUtil;

import java.io.File;
import java.util.*;

public class Test {
    public static void main(String[] args) {
        HashMap map = new HashMap();
        File file = FileUtil.file("D:\\javabase_ws\\javaAdvanceProject\\day14_threadpool_net\\src\\com\\itheima\\zuoye\\zy1\\work.txt");
        String s = FileUtil.readUtf8String(file);
        String[] split = s.split(",");

        for (String item : split) {
            item = item.trim(); // 去掉前后空格
            if (!item.isEmpty()) {
                map.put(item, (int) map.getOrDefault(item, 0) + 1);
            }
        }
        //        统计每个数据出现的次数，并打印出现次数最多的6个数据
        List<Map.Entry<String, Integer>> list = new ArrayList<>(map.entrySet());
        Collections.sort(list, (o1, o2) -> o2.getValue() - o1.getValue());
        for (int i = 0; i < 6; i++) {
            System.out.println(list.get(i));
        }

    }
}
